% \iffalse meta-comment ---------------------------------------------
% Copyright (C) Shanghai Jiao Tong University
% The definition in this file is referred to the Visual Identity System
% from Shanghai Jiao Tong University (SJTU). 
% See https://vi.sjtu.edu.cn for more information.
% 
% SJTUG implements the design but doesn't hold the copyright.
% Any commercial usage in this file should be acknowledged by
% the administration of SJTU.
% More information about the license,
% see https://vi.sjtu.edu.cn/index.php/articles/bulletin/16. 
% ------------------------------------------------------------------- \fi
% \iffalse
%<*package>
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{sjtucover}[2024/12/21 v3.1.1 cover library for sjtubeamer]
%</package>
% \fi
% \CheckSum{0}
% \StopEventually{}
% \iffalse
%<*package>
% ------------------------------------------------------------------- \fi
%
% \subsection{Cover Library}
% This library provides the template for the title page and the bottom page.
%
% \subsubsection{Load Packages}
%
% Load SJTU VI Library to get the definition on shapes.
% This will also provide \verb"\sjtubeamer@compatible" option.
%    \begin{macrocode}
\RequirePackage{sjtuvi}
%    \end{macrocode}
%
% \subsubsection{Define Option}
%
%    \begin{macrocode}
\DefineOption{cover}{lang}{zh}
\DefineOption{cover}{lang}{en}
\@ifclassloaded{ctexbeamer}{\ExecuteOptionsBeamer{zh}}{
  \ExecuteOptionsBeamer{en}}
\ProcessOptionsBeamer
%    \end{macrocode}
%
% \subsubsection{Logo}
% \paragraph{max.}
%    \begin{macrocode}
%<*max>
\defbeamertemplate*{logo}{max}{\resizebox{!}{1cm}{\sjtubadge}}
%</max>
%    \end{macrocode}
%
%   \paragraph{default.}
%    \begin{macrocode}
\if\EqualOption{cover}{lang}{zh}
  \defbeamertemplate*{logo}{default}{\resizebox{!}{0.7cm}{\zhlogo}}
\else
  \defbeamertemplate*{logo}{default}{\resizebox{!}{0.7cm}{\enlogo}}
\fi
%    \end{macrocode}
%
% \subsubsection{Title Graphic}
% \paragraph{maxplus.}
%    \begin{macrocode}
%<*maxplus>
\defbeamertemplate*{sjtutitlegraphic}{maxplus}{\includegraphics{vi/sjtu-vi-sjtuphoto.jpg}}
%</maxplus>
%    \end{macrocode}
%
% \paragraph{max.}
%    \begin{macrocode}
%<*max>
\defbeamertemplate*{sjtutitlegraphic}{max}{\sjtubg[opacity=0.2]}
%</max>
%    \end{macrocode}
%
% \paragraph{min.}
%    \begin{macrocode}
%<*min>
\defbeamertemplate*{sjtutitlegraphic}{min}{\includegraphics{vi/sjtu-vi-sjtuphoto.jpg}}
%</min>
%    \end{macrocode}
%
% \paragraph{my.}
%    \begin{macrocode}
%<*my>
\defbeamertemplate*{sjtutitlegraphic}{my}{
  %
  % Developer could define your title graphic here for "my"...
  %
}
%</my>
%    \end{macrocode}
%
% \subsubsection{Title Page}
%  
% \paragraph{maxplus.}
%    \begin{macrocode}
%<*maxplus>
\defbeamertemplate*{title page}{maxplus}[1][]
{
  \vbox{}
  \vfill
  \begingroup
  \usebeamercolor{palette primary}% 
  \begin{tikzpicture}[overlay,
      xshift=-0.12\paperwidth,
      yshift=-0.53\paperheight]
    \pgfmathsetlengthmacro{\outslant}{1.02\paperwidth}
    \node[inner sep=0, outer sep=0]
      at (0.57\paperwidth,0.5\paperheight){
        \resizebox{!}{1.06\paperheight}{\vphantom{-}\inserttitlegraphic}};
    \fill[color=white] (0,0) rectangle(1.1\paperwidth,3.9);
    \fill[color=bg]  (0,-0.1\paperheight) rectangle(1.1\paperwidth,3.88);
    \node[anchor=north west, text width=.8\paperwidth]
    at (0.11\paperwidth,3.6){%
    \usebeamercolor[fg]{title}
    \ifx\insertsubtitle\@empty%
      {\huge\bfseries\inserttitle}\\
      \else%
      {\Large\bfseries\inserttitle}\\
      {\small\insertsubtitle}\\
    \fi%
    };
    \node[anchor=south west, text width=.8\paperwidth] at (0.11\paperwidth,0.45){%
      {\usebeamercolor[fg]{author}\small\insertauthor\par}
        {\usebeamercolor[fg]{institute}\small\insertinstitute\par}
        {\usebeamercolor[fg]{date}\small\insertdate}%
    };
    \node[anchor=south east, inner sep=0, outer sep=0] at ({\outslant-5pt},0.5){
      \usebeamercolor[fg]{palatte primary}
      \resizebox{!}{1cm}{\vphantom{-}\usebeamertemplate{logo}}
    };
  \end{tikzpicture}
  \endgroup
  \vfill
}
%</maxplus>
%    \end{macrocode}
%  
% \paragraph{max.}
%    \begin{macrocode}
%<*max>
\defbeamertemplate*{title page}{max}[1][]
{
  \vbox{}
  \usebeamercolor{palette primary}
  \begin{tikzpicture}[overlay]
    \fill [palette primary.bg] (-0.2*\the\paperwidth,-1*\the\paperheight)
    rectangle (1*\the\paperwidth, 0.3*\the\paperheight);
    \node [palette primary.fg, inner sep=0pt]
    at (0.45\paperwidth-6pt,-0.4*\the\paperheight)
    {\resizebox{1.3\paperwidth}{!}{\vphantom{-}\inserttitlegraphic}};
  \end{tikzpicture}
  \vfill
  \begingroup
  \begin{beamercolorbox}[sep=8pt,#1,center]{title}
    \usebeamerfont{title}\inserttitle\par%
    \ifx\insertsubtitle\@empty%
    \else%
      \vskip0.25em%
      {\usebeamerfont{subtitle}\insertsubtitle\par}%
    \fi%     
  \end{beamercolorbox}%
  \vskip1em\par
  \begin{beamercolorbox}[sep=8pt,#1,center]{author}
    \usebeamercolor[fg]{palette primary}
    \usebeamerfont{author}\insertauthor
  \end{beamercolorbox}
  \begin{beamercolorbox}[sep=8pt,#1,center]{institute}
    \usebeamercolor[fg]{palette primary}
    \usebeamerfont{institute}\normalsize\insertinstitute
  \end{beamercolorbox}
  \begin{beamercolorbox}[sep=8pt,#1,center]{date}
    \usebeamercolor[fg]{palette primary}
    \usebeamerfont{date}\insertdate
  \end{beamercolorbox}
  \endgroup
  \vfill
}
%</max>
%    \end{macrocode}
%
% \paragraph{min.}
% Declare two fadings: center fade and fade right.
% The center fade provides a radial fading on the right side of the title page.
% The fade right provides a linear fading to avoid the collision on the text in the left.
%    \begin{macrocode}
%<*min>
\tikzfading[
  name=center fade,
  inner color=transparent!0,
  outer color=transparent!15
]
\tikzfading[
  name=fade right,
  left color=transparent!0,
  right color=transparent!100
]
%    \end{macrocode}
%
%    \begin{macrocode}
\defbeamertemplate*{title page}{min}[1][]
{
  \vbox{}
%    \end{macrocode}
% The background of the title page is implemented by a TikZ rectangle,
% which avoids the changing on \verb"background canvas" beamer color. 
%
% In this definition environment, you could not change the beamer color.
% The older version redefines \verb"maketitle" command and switches the
% \verb"background canvas" color, which is harmful for decoupling. 
%
% Use TikZ rectangle also avoids the unexpected shift because the risk of
% redefining the internal command is avoided.
% If there is any text before the title page, the \verb"\maketitle" will
% start from a new page.
%    \begin{macrocode}
  \usebeamercolor{palette primary}
  \begin{tikzpicture}[overlay]
    \fill [palette primary.bg] (-0.2*\the\paperwidth,-1*\the\paperheight)
    rectangle (1*\the\paperwidth, 0.2*\the\paperheight);
  \end{tikzpicture}
%    \end{macrocode}
%
% If it is in draft mode or it is not compatible, no pattern will get rendered.
%
% Otherwise, the fade tile of stamp array will get covered on top of the
% background rectangle.
%
% \verb"stamparray" is defined in \verb"sjtuvi". Then, a fade right covers this
% array layer and a center fade covers the previous result.
%    \begin{macrocode}
  \ifx\sjtubeamer@compatible\sjtubeamer@compatible@false
  \else
    \ifbeamer@draftmode%
    \else%
      \begin{tikzpicture}[overlay]
        \stamparray{20pt}
        {(-0.2*\the\paperwidth,-1*\the\paperheight)}
        {(1*\the\paperwidth, 0.2*\the\paperheight)}
        \fill [bg,path fading=fade right]
        (-0.2*\the\paperwidth,-1*\the\paperheight) rectangle
        (1*\the\paperwidth, 0.2*\the\paperheight);
        \fill [bg,path fading=center fade,xshift=-10pt,yshift=-20pt]
        (0.2*\the\paperwidth,0) circle [radius=\the\paperwidth];
      \end{tikzpicture}
    \fi%
  \fi
%    \end{macrocode}
% Set a constraint in the vertical mode to make the following contents centered
% in the middle of the slide.
%    \begin{macrocode}
  \vfill
  \begingroup
  \centering
%    \end{macrocode}
% \verb"resizebox" is used to adapt to all size of logo into 1cm height one.
% And it is the same in outer theme to make a 0.7cm logo.
%
% The institute is in \TeX{} code for typesetting. \verb"\beamer@shortinstitute"
% meta is used to avoid compressing on \verb"\par", while \verb"\insertinstitute"
% will force the input to spread on one signle line.
% The mode to use is depended on the \verb"language" option.
% Super small font could be made by \verb"fontsize".
%
% NOTE: When you use the picture as the secondary institute, make sure it is the
% parameter that will be displayed.
% For \verb"zh" option, the optional parameter should leaved as empty explicitly,
% i.e., \verb"\institute[]{<pic>}", otherwise the shortinstitute will be the same
% as the main parameter.
% For \verb"en" option, the optional parameter should be the picture,
% i.e., \verb"\institute[<pic>]{}". The picture should be 0.95cm in height,
% as noted in \verb"\secondaryinstlogo" in \verb"sjtuvi".
%
% FIXME: since the logo has some tiny margin, the left alignment seems not so perfect.
% Hence a -0.6pt visual compensation is added to address the issue.
% This will be fixed in the future through a better clip and safe margin control
% on \verb"\definelogo".
%    \begin{macrocode}
  \begin{beamercolorbox}[sep=8pt,#1]{empty}
    \usebeamercolor[fg]{palette primary}%
    \hspace*{-0.6pt}%
    \if\EqualOption{cover}{lang}{en}%
      \secondaryinstlogo{\beamer@shortinstitute}{\usebeamertemplate{logo}}
    \else%
      \secondaryinstlogo[\insertshortinstitute]{\insertinstitute}{\usebeamertemplate{logo}}
    \fi%
  \end{beamercolorbox}
%    \end{macrocode}
% Insert title, subtitle, author, and date.
%    \begin{macrocode}
  \begin{beamercolorbox}[sep=8pt,#1]{title}
    \usebeamerfont{title}\inserttitle\par%
    \ifx\insertsubtitle\@empty%
    \else%
      \vskip0.25em%
      {\usebeamerfont{subtitle}\insertsubtitle\par}%
    \fi%     
  \end{beamercolorbox}%
  \vskip1em\par
  \begin{beamercolorbox}[sep=8pt,#1]{author}
    \usebeamerfont{author}\insertauthor
  \end{beamercolorbox}
  \begin{beamercolorbox}[sep=8pt,#1]{date}
    \usebeamerfont{date}\insertdate
  \end{beamercolorbox}
%    \end{macrocode}
% Here insert the titlegraphic. The node position is set to \verb"above left" to
% make sure the bottom of the picture is aligned to the bottom of the date line.
%
% The size specification should be the same as \verb"stampbox" in the inner theme.
% Since we need a finer control on the position of the picture and the inner theme
% is the upper layer of this style file, the whole thing should be reimplemented here.
%
% \changes{v3.1.0}{2024/10/21}{Fix the condition of empty titlegraphic in
% \texttt{min} theme.}
% \changes{v3.1.1}{2024/12/21}{Revert to the original condition of empty titlegraphic in
% \texttt{min} theme.}
%    \begin{macrocode}
  \usebeamercolor{palette primary}% 
  \ifx\inserttitlegraphic\@empty%
  \else
    \begin{tikzpicture}[overlay, yshift=1.2em]
      \node (pic) [fg, above left, inner sep=0.32em] at (0.86\paperwidth,0)
      {\resizebox{0.3\paperwidth}{!}{\inserttitlegraphic}};
      \draw[decoration={
            stampline,
            segment length=0.8em,
            path has corners=true,
          },decorate,fg]
      (pic.north west) --
      (pic.north east) --
      (pic.south east) --
      (pic.south west) -- cycle;
    \end{tikzpicture}
  \fi
  \endgroup
  \vskip0.5em
  \vfill
}
%</min>
%    \end{macrocode}
%  
% \paragraph{my.}
%    \begin{macrocode}
%<*my>
\defbeamertemplate*{title page}{my}[1][]{
  %
  % Developer could implement your own title page template here...
  % or use "my" theme first, then implement your title page 
  % in a different style file mycover.sty with:
  %    \defbeamertemplate*{title page}{<another name>}[1][]{<Your implementation>}
  %    \setbeamertemplate{title page}[<another name>]
  % and in the main.tex:
  %    \usetheme[my]{sjtubeamer}\usepackage{mycover}
  %
}
%</my>
%    \end{macrocode}
%
% \subsubsection{Bottom Page}
%
% \begin{macro}{\bottomthanks}
% The "Thank You" caption in the bottom
% page. Redefine this command will change
% the bottom page caption.
%    \begin{macrocode}
\if\EqualOption{cover}{lang}{zh}%
  \newcommand{\bottomthanks}{谢\,谢}
\else%
  \newcommand{\bottomthanks}{Thank You}
\fi%
%    \end{macrocode}
% \end{macro}
%
% Bottom page could be generated by \verb"\makebottom" command.
%
% \paragraph{maxplus.}
%    \begin{macrocode}
%<*maxplus>
\tikzfading[name=fade right img,
  left color=transparent!20,
  right color=transparent!100]
\defbeamertemplate*{bottom page}{maxplus}[1][]
{
  \vbox{}
  \begin{tikzpicture}[overlay]
    \usebeamercolor{palette primary}
    \fill[palette primary.bg] (-0.2\paperwidth,-\paperheight)
    rectangle (\paperwidth, 0.5\paperheight);
  \end{tikzpicture}
  \vfill
  \begin{beamercolorbox}[sep=0pt]{empty}
    \usebeamercolor{structure}
    \begin{tikzpicture}[overlay,xshift=0.54\paperwidth,yshift=-0.41\paperheight]
      \begin{scope}
        \clip (-0.66\paperwidth,0.06\paperheight)
        rectangle (0.43\paperwidth,0.53\paperheight);
        \node [anchor=north] at (0,0.645\paperheight) {
          \resizebox{1.33\paperwidth}{!}{\vphantom{-}\inserttitlegraphic}};
        \fill[structure.fg!50!black,path fading=fade right img]
        (-0.66\paperwidth,0.06\paperheight)
        rectangle (0.43\paperwidth,0.53\paperheight);
        \node[white] at (-0.45\paperwidth,0.3\paperheight)
        {\resizebox{!}{0.115\paperheight}{\vphantom{-}\usebeamertemplate{logo}}};
        \node [right, white] at (-0.75\paperwidth, 0.15\paperheight) 
        {\resizebox{1.15\paperwidth}{!}{\sjtugate}};
      \end{scope}
      \node at (-0.13\paperwidth,0.7\paperheight) {
        \usebeamercolor[fg]{title}
        \LARGE \bfseries \bottomthanks
      };
    \end{tikzpicture}
  \end{beamercolorbox}
  \vfill
}
%</maxplus>
%    \end{macrocode}
%
% \paragraph{max.}
%    \begin{macrocode}
%<*max>
\defbeamertemplate*{bottom page}{max}[1][]
{
  \vbox{}
  \usebeamercolor{palette primary}
  \usebeamercolor{structure}
  \begin{beamercolorbox}[sep=0pt]{empty}
    \begin{tikzpicture}[overlay,yshift=0.25\paperwidth]
      \def\leftw{0.215\paperwidth}
      \def\midw{0.435\paperwidth}
      \def\rightw{0.655\paperwidth}
      \fill[palette primary.bg] (-0.2\paperwidth,-1.2\paperheight) rectangle
      (\paperwidth, 0.1\paperheight);
      \fill[palette primary.fg] (\leftw,0.1\paperheight)
      -- (\leftw,-0.5\paperheight)
      -- (\midw,-0.65\paperheight)
      -- (\rightw,-0.5\paperheight)
      -- (\rightw,0.1\paperheight) -- cycle;
      \fill[palette primary.fg] (\leftw,-0.53\paperheight)
      -- (\leftw,-0.59\paperheight)
      -- (\midw,-0.74\paperheight)
      -- (\rightw,-0.59\paperheight)
      -- (\rightw,-0.53\paperheight)
      -- (\midw,-0.68\paperheight) -- cycle;
      \node[black] at (\midw,-0.65\paperheight) {
        \resizebox{1.25\paperwidth}{!}{\vphantom{-}\inserttitlegraphic}};
      \node[palette primary.bg] at (\midw,-0.2\paperheight) 
        {\resizebox{!}{2.5cm}{\vphantom{-}\usebeamertemplate{logo}}};
      \node at (\midw,-0.45\paperheight) {
        \usebeamercolor[bg]{palette primary}
        \LARGE \bfseries\bottomthanks};
    \end{tikzpicture}
  \end{beamercolorbox}
}
%</max>
%    \end{macrocode}
%
% \paragraph{min.}
%    \begin{macrocode}
%<*min>
\defbeamertemplate*{bottom page}{min}[1][]
{
%    \end{macrocode}
% Leave vertical mode, which is equivalent to \verb"\leavevmode".
%    \begin{macrocode}
  \vbox{}
%    \end{macrocode}
% Create the background canvas and the three overlapping circles in the right.
% Use \verb"scope" to define the influence range.
% And use \verb"\clip" to make the clipping in the current range.
%    \begin{macrocode}
  \usebeamercolor{palette primary}
  \usebeamercolor{palette secondary}
  \begin{tikzpicture}[overlay,yshift=-80pt]
    \def\w{\the\paperwidth}%
    \def\h{\the\paperheight}%
    \fill [palette primary.bg] (-0.2*\w,-1*\h) rectangle (1*\w, 0.5*\h);
    \begin{scope}[fill=palette primary.bg!50!palette primary.fg,fill opacity=0.15]
      \clip (0.63*\w,1.05*\h) circle (1*\h);
      \fill (0.14*\w,-0.95*\h) circle (1.67*\h);
    \end{scope}
    \begin{scope}
      [fill=palette secondary.bg!50!palette primary.bg!70!palette primary.fg,
        fill opacity=0.15]
      \clip[xshift=26pt] (0.95*\w,-0.67*\h) circle (1.17*\h);
      \fill
      (0.14*\w,-0.95*\h) circle (1.67*\h)
      (0.63*\w,1.05*\h) circle (1*\h);
    \end{scope}
  \end{tikzpicture}
%    \end{macrocode}
% Insert the logo in the crossing center of the overlapping circles.
%    \begin{macrocode}
  \vfill
  \usebeamercolor[fg]{palette primary}
  \begingroup
  \raggedleft
  \resizebox{!}{1cm}{\vphantom{-}\usebeamertemplate{logo}}
%    \end{macrocode}
% Inset the ``thank you'' quote and the title of this beamer.
% Notice that three \verb"\vfill" divide the frame into three portions with
% final adjust using \verb"\vskip".
%    \begin{macrocode}
  \vfill
  \vskip6em
  \begin{beamercolorbox}[sep=8pt]{title}
    \usebeamerfont{title}\noindent\bottomthanks
    \vskip1em%
    \usebeamerfont{subtitle}
    \insertauthor
    \ifx\insertauthor\@empty
    \else
      \ifx\inserttitle\@empty
      \else~$\cdot$~\fi
    \fi
    \inserttitle
  \end{beamercolorbox}%
  \vfill
  \vskip3.5em
  \endgroup
}
%</min>
%    \end{macrocode}
%
% \paragraph{my.}
%    \begin{macrocode}
%<*my>
\defbeamertemplate*{bottom page}{my}[1][]
{
  %
  % Developer could implement your own bottom page template here...
  % or use "my" theme first, then implement your title page 
  % in a different style file mycover.sty with:
  %    \defbeamertemplate*{bottom page}{<another name>}[1][]{<Your implementation>}
  %    \setbeamertemplate{bottom page}[<another name>]
  % and in the main.tex:
  %    \usetheme[my]{sjtubeamer}\usepackage{mycover}
  %
}
%</my>
%    \end{macrocode}
%
% \subsubsection{Name Translation}
%
%    \begin{macrocode}
\if\EqualOption{cover}{lang}{zh}%
  \@ifclassloaded{ctexbeamer}{
%    \end{macrocode}
% \begin{macro}{\sjtubeamer@cover@partnumber}
% Part number based on different languages
% and whether the \verb"ctexbeamer" class
% is loaded.
%
% If \verb"ctexbeamer" is loaded, you could
% modify the \verb"part/number" by
% \verb"\ctexset" after the theme is loaded.
%    \begin{macrocode}
    \def\sjtubeamer@cover@partnumber{\CTEX@thepart}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\sjtubeamer@cover@partname}
% Part name based on different languages
% and whether the \verb"ctexbeamer" class
% is loaded.
%
% If \verb"ctexbeamer" is loaded, you could
% modify the \verb"part/name" by \verb"\ctexset"
% after the theme is loaded.
%    \begin{macrocode}
    \def\sjtubeamer@cover@partname{\CTEX@partname}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\sjtubeamer@cover@sectionnumber}
% Section number based on whether the
% \verb"ctexbeamer" class is loaded.
%
% If \verb"ctexbeamer" is loaded, you could
% modify the \verb"section/number" by
% \verb"\ctexset" after the theme is loaded.
%    \begin{macrocode}
    \def\sjtubeamer@cover@sectionnumber{\CTEX@thesection}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\sjtubeamer@cover@sectionname}
% Section name based on different languages
% and whether the \verb"ctexbeamer" class
% is loaded.
%
% If \verb"ctexbeamer" is loaded, you could
% modify the \verb"section/name" by
% \verb"\ctexset" after the theme is loaded.
%
% The default value for \verb"section/name"
% is modified to the full text description
% version instead of pure value version.
%    \begin{macrocode}
    \ctexset{section/name={第~,~节}}
    \def\sjtubeamer@cover@sectionname{\CTEX@sectionname}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\sjtubeamer@cover@subsectionnumber}
% Subsection number based on different
% languages and whether the \verb"ctexbeamer"
% class is loaded. 
%
% If \verb"ctexbeamer" is loaded, you could
% modify the \verb"subsection/number" by
% \verb"\ctexset" after the theme is loaded.
%    \begin{macrocode}
    \def\sjtubeamer@cover@subsectionnumber{\CTEX@thesubsection}
%    \end{macrocode}
% \end{macro}
% \begin{macro}{\sjtubeamer@cover@subsectionname}
% Subsection name based on whether the
% \verb"ctexbeamer" class is loaded.
%
% If \verb"ctexbeamer" is loaded, you could
% modify the \verb"subsection/name" by
% \verb"\ctexset" after the theme is loaded.
%
% The default value for \verb"subsection/name"
% is modified to the full text description
% version instead of pure value version.
%    \begin{macrocode}
    \ctexset{subsection/name={第~,~小节}}
    \def\sjtubeamer@cover@subsectionname{\CTEX@subsectionname}
%    \end{macrocode}
% \end{macro}
%    \begin{macrocode}
  }{
%    \end{macrocode}
% The branch here is prepared just in case that the \verb"beamer" is loaded
% and \verb"ctex" package is manually loaded, with \verb"zh" option turned on.
%    \begin{macrocode}
    \def\sjtubeamer@cover@partnumber{\insertromanpartnumber}
    \def\sjtubeamer@cover@partname{第~\sjtubeamer@cover@partnumber~部分}
    \def\sjtubeamer@cover@sectionnumber{\insertsectionnumber}
    \def\sjtubeamer@cover@sectionname{第~\sjtubeamer@cover@sectionnumber~节}
    \def\sjtubeamer@cover@subsectionnumber{\insertsubsectionnumber}
    \def\sjtubeamer@cover@subsectionname{第~\sjtubeamer@cover@subsectionnumber~小节}
  }
\else%
    \def\sjtubeamer@cover@partnumber{\insertromanpartnumber}
    \def\sjtubeamer@cover@partname{\partname~\sjtubeamer@cover@partnumber}
    \def\sjtubeamer@cover@sectionnumber{\insertsectionnumber}
    \def\sjtubeamer@cover@sectionname{\sectionname~\sjtubeamer@cover@sectionnumber}
    \def\sjtubeamer@cover@subsectionnumber{\insertsubsectionnumber}
    \def\sjtubeamer@cover@subsectionname{\subsectionname~\sjtubeamer@cover@subsectionnumber}
\fi
%    \end{macrocode}
%
% \subsubsection{Sectioning Page}
%
% \begin{macro}{\definesecpage}
% Define the beamer template for
% \verb"part page", \verb"section page",
% \verb"subsection page" for cover style
% \verb"maxplus", \verb"max", \verb"min".
%
% Use a parent template \verb"sectioning page"
% for the different variantions on different
% sectype (\#1).
% \verb"sectioning page" for different cover
% (\#2) will be defined later.
%    \begin{macrocode}
\def\definesecpage#1#2{
  % #1: sectype (part, section, subsection)
  % #2: cover   (maxplus, max, min)
  \defbeamertemplate*{#1 page}{#2}[1][]{
    {
      \setbeamertemplate{sectioning page}[#2]{#1}
      \usebeamertemplate{sectioning page}
    }
  }
}
%    \end{macrocode}
% A \verb"sectioning block" helper beamer template may also be introduced for
% the convinience of reuse the same basic block for subsectionpage.
% \end{macro}
%
% \paragraph{maxplus.}
%    \begin{macrocode}
%<*maxplus>
\defbeamertemplate*{sectioning block}{maxplus}[1]
{
  \usebeamercolor[fg]{#1 title}
  \usebeamerfont{#1 name}
  \csname sjtubeamer@cover@#1name\endcsname
  \par\vskip4pt
  {\usebeamerfont{#1 title}\csname insert#1\endcsname\par}
}
\defbeamertemplate*{sectioning page}{maxplus}[1]
{
  \vbox{}
  \def\sjtubeamer@cover@sectype{#1}
  \usebeamercolor{#1 title}
  \begin{tikzpicture}[overlay]
    \fill [bg] (-0.2*\the\paperwidth,-1*\the\paperheight)
    rectangle (1*\the\paperwidth, 0.4*\the\paperheight);
    \node [right, fg] at (-0.2*\the\paperwidth, -0.5*\the\paperheight)
    {\resizebox{1.15\paperwidth}{!}{\sjtugate}};
  \end{tikzpicture}
  \vfil
  \begingroup
    \if\EqualOption{cover}{sectype}{subsection}
      \setbeamertemplate{sectioning block}[maxplus]{section}
      \usebeamertemplate{sectioning block}
      \vskip10pt
    \fi
    \setbeamertemplate{sectioning block}[maxplus]{#1}
    \usebeamertemplate{sectioning block}
    \if\EqualOption{cover}{sectype}{part}
      \vskip10pt
      {
        \scriptsize
%    \end{macrocode}
% The workaround to insert the vertical section navigation.
% \verb"\hfuzz" is locally set to ignore the overfull box.
% \verb"\hbadness" is set to a value bigger than infinity (10000) to ignore the underfull box.
% \verb"\hskip" is set for the compensation from the macro \verb"\insertsectionnavigation".
% The width of section navigation is set to a small value to force the text to ``flushleft'',
% but with the hyperlink area maintained.
%    \begin{macrocode}
        \hfuzz=100pt
        \hbadness=100000
        \hskip-0.3cm
        \insertsectionnavigation{0.5cm}
      }
    \fi
  \endgroup
%    \end{macrocode}
% Add additional vertical skip for the section page, to align with the subsection page
% on bottom gate picture.
%    \begin{macrocode}
  \if\EqualOption{cover}{sectype}{section}
    \vskip8.5ex
  \fi
  \vfill
}
%    \end{macrocode}
%
% Overide the default beamer template of \verb"part page", \verb"section page",
% \verb"subsection page" for cover style \verb"maxplus".
%    \begin{macrocode}
\definesecpage{part}{maxplus}
\definesecpage{section}{maxplus}
\definesecpage{subsection}{maxplus}
%</maxplus>
%    \end{macrocode}
%
%
% \paragraph{max.}
%
% \begin{macro}{\ifbeamercolorwhite}
% A helper function like \verb"\ifbeamercolorempty"
% to check if the color is white (only the
% literal layer, without any expansion).
%
% Two mandantory parameters: 
% The first one indicates if it is fg or bg.
% The second one is the beamer color name.
%    \begin{macrocode}
\def\ifbeamercolorwhite#1#2{%
  % #1: fg or bg
  % #2: beamer color name
  \beamer@thc@prepcolor%
  \beamer@thc@docolor{#2}%
  \def\beamer@temp{white}%
  \expandafter\ifx\csname beamer@thc@#1\endcsname\beamer@temp%
    \expandafter\@firstoftwo%
  \else%
    \expandafter\@secondoftwo%
  \fi%
}
%    \end{macrocode}
% COPYRIGHT NOTICE: This macro is modified from \verb"beamer" class under LPPL 1.3c license.
%
% For decoupling reason, without passing the lum option (dark or light) to make
% judgement on the primary color which is not white.
% This might be helpful if you do not want the color to get changed by the lum option.
% \end{macro}
%
%    \begin{macrocode}
%<*max>
\defbeamertemplate*{sectioning block}{max}[1]
{
  \usebeamercolor{#1 title}
  \ifbeamercolorwhite{fg}{#1 title}{\color{bg}}{\color{fg}}
  \stamptext[.]{\large\csname sjtubeamer@cover@#1number\endcsname}\\
  \vskip8pt
  {
    \usebeamerfont{#1 title}
    \csname insert#1\endcsname
    \par
  }
}
\defbeamertemplate*{sectioning page}{max}[1]
{
  \vfill
  \begingroup
    \centering
    \def\sjtubeamer@cover@sectype{#1}
    \if\EqualOption{cover}{sectype}{subsection}
      \setbeamertemplate{sectioning block}[max]{section}
      \usebeamertemplate{sectioning block}
      \vskip16pt
    \fi
    \setbeamertemplate{sectioning block}[max]{#1}
    \usebeamertemplate{sectioning block}
  \endgroup
  \vfill
}
%    \end{macrocode}
%
% Overide the default beamer template of \verb"part page", \verb"section page",
% \verb"subsection page" for cover style \verb"max".
%    \begin{macrocode}
\definesecpage{part}{max}
\definesecpage{section}{max}
\definesecpage{subsection}{max}
%</max>
%    \end{macrocode}
%
% \paragraph{min.}
%    \begin{macrocode}
%<*min>
\defbeamertemplate*{sectioning block}{min}[1]
{
  \begin{beamercolorbox}[sep=12pt,right]{#1 title}
    \usebeamerfont{#1 name}
    \csname sjtubeamer@cover@#1name\endcsname
    \par\vskip4pt
    \usebeamerfont{#1 title}\csname insert#1\endcsname\par
  \end{beamercolorbox}
}
\defbeamertemplate*{sectioning page}{min}[1]
{
  \vfill
  \vskip 8pt
  \begingroup
  \def\sjtubeamer@cover@sectype{#1}
  \if\EqualOption{cover}{sectype}{part}
    \begin{beamercolorbox}[sep=16pt,right]{part title}
      \hfill\usebeamerfont{part name}
      \sjtubeamer@cover@partname
      \par\vskip4pt
      \usebeamerfont{part title}\insertpart\par
%    \end{macrocode}
% Since navigation bar is packaged, to modify the color, you have to change the
% \verb"section in head/foot" beamer color.
% Here, use a group to make the temporary change.
%
% Instead of using \verb"\insertnavigation" macro, use \verb"\insertsectionnavigationhorizontal"
% macro for a better control of long navigation bar.
%    \begin{macrocode}
      \hbox to \textwidth{
        {
          \usebeamerfont{footline}
          \setbeamercolor{section in head/foot}{use=palette primary,
            fg=palette primary.fg,bg=}
          \let\navwidth\textwidth
          \advance\navwidth by -32pt
          \insertsectionnavigationhorizontal{\navwidth}{\hskip0pt plus1filll}{\hskip-.3cm}
          \hskip11pt
        }
      }
    \end{beamercolorbox}
  \else
    \if\EqualOption{cover}{sectype}{subsection}
      \setbeamertemplate{sectioning block}[min]{section}
      \usebeamertemplate{sectioning block}
    \fi
    \setbeamertemplate{sectioning block}[min]{#1}
    \usebeamertemplate{sectioning block}
  \fi
  \endgroup
  \vfill
}
%    \end{macrocode}
%
% Overide the default beamer template of \verb"part page", \verb"section page",
% \verb"subsection page" for cover style \verb"min".
%    \begin{macrocode}
\definesecpage{part}{min}
\definesecpage{section}{min}
\definesecpage{subsection}{min}
%</min>
%    \end{macrocode}
%
% \paragraph{my.}
%    \begin{macrocode}
%<*my>
\defbeamertemplate*{part page}{my}[1][]
{
  %
  % Developer could implement your own part page template here...
  % or use "my" theme first, then implement your part page 
  % in a different style file mycover.sty with:
  %    \defbeamertemplate*{part page}{<another name>}[1][]{<Your implementation>}
  %    \setbeamertemplate{part page}[<another name>]
  % and in the main.tex:
  %    \usetheme[my]{sjtubeamer}\usepackage{mycover}
  %
}
\defbeamertemplate*{section page}{my}[1][]
{
  %
  % Developer could implement your own section page template here...
  % or use "my" theme first, then implement your section page 
  % in a different style file mycover.sty with:
  %    \defbeamertemplate*{section page}{<another name>}[1][]{<Your implementation>}
  %    \setbeamertemplate{section page}[<another name>]
  % and in the main.tex:
  %    \usetheme[my]{sjtubeamer}\usepackage{mycover}
  %
}
\defbeamertemplate*{subsection page}{my}[1][]
{
  %
  % Developer could implement your own subsection page template here...
  % or use "my" theme first, then implement your subsection page 
  % in a different style file mycover.sty with:
  %    \defbeamertemplate*{subsection page}{<another name>}[1][]{<Your implementation>}
  %    \setbeamertemplate{subsection page}[<another name>]
  % and in the main.tex:
  %    \usetheme[my]{sjtubeamer}\usepackage{mycover}
  %
}
%</my>
%    \end{macrocode}
%
% \iffalse
%</package>
% \fi
%
% \Finale
\endinput
